
use "$data/clean/clean_main_complete.dta" , replace


tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 6

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear



gen pana=.
gen panb=.
gen panc=.
gen pand=.
gen pane=.
gen intt= .
gen empt =. 
gen part_aff = .

label var pana "\underline{Individual level characteristics} " 
label var panb "\underline{Prior experience} " 

label var empt " "
  
  foreach yvar of varlist pana  female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 empt panb d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others  empt  {
	qui sum `yvar', d
	if `r(N)'!=0 {
	qui sum `yvar' if  control ==1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	
	qui sum `yvar' if voice_instrumental_pooled == 1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col2
	
		qui sum `yvar' if voice_intrinsic_pooled == 1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col3
	
	
	reg `yvar'  voice_instrumental_pooled voice_intrinsic_pooled, r

	
	test voice_instrumental_pooled
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col4
	
	
	test voice_intrinsic_pooled
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col5

	test voice_instrumental_pooled=voice_intrinsic_pooled
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col6


	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1
}

  

/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"

esttab col* using "$output/balance_pooled_instrumental", booktabs cells(none) nogap mtitle("Control" "Instrumental" "Intrinsic"  "p(Inst=Cont)"  "p(Intr=Cont)"  "p(Intr=Inst)" ) ///
 stats(`statnames', labels(`varlabels'))  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear



reg  voice_instrumental_pooled female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others , r

test female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others
 
 
 
 reg  voice_intrinsic_pooled female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others , r

test female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others

